package com.casic.ops.entity.vo.pipeline;

import com.casic.ops.consts.app.PipelineStatus;
import com.casic.ops.entity.domain.ApplicationPipelineTaskDO;
import com.casic.ops.entity.domain.pipeline.PipelineLoggerDO;
import com.casic.ops.entity.vo.ApplicationPipelineTaskStatisticsDetailVO;
import com.casic.ops.entity.vo.ApplicationPipelineTaskStatisticsTaskVO;
import com.casic.ops.utils.Utils;
import lombok.Data;

import java.util.Date;
import java.util.List;
@Data
public class PipelineStaticsLoggerVO {
    /**
     * id
     */
    private Long id;

    /**
     * uuid
     */
    private Long uuid;

    /**
     * 标题,目前暂时标题即pipelineName;
     */
    private String title;

    /**
     * 执行时间
     */
    private Date execDate;

    /**
     * 执行状态 10待审核 20审核驳回 30待执行 35待调度 40执行中 50执行完成 60执行停止 70执行失败
     *
     * @see PipelineStatus
     */
    private Integer status;

    /**
     * 执行操作时长ms (成功)
     */
    private Long used;

    /**
     * 执行操作时长 (成功)
     */
    private String usedInterval;

    /**
     * 执行操作
     */
    private List<PipelineStaticsticsNodeloggerVO> details;

    public static PipelineStaticsLoggerVO pipelineLoggerDO2pipelineStatisticsLoggerVO(PipelineLoggerDO p) {
        PipelineStaticsLoggerVO vo = new PipelineStaticsLoggerVO();
        vo.setId(p.getId());
        vo.setUuid(p.getUuid());
        vo.setExecDate(p.getExecuteStartTime());
        if(p.getFinalStatus().equals("失败")) {
            vo.setStatus(70);
        }else {
            vo.setStatus(50);
        }
        // 设置构建用时
        String success="成功";
        if (success.equals(p.getFinalStatus())
                && p.getExecuteStartTime() != null
                && p.getExecuteEndTime() != null) {
            long used = p.getExecuteEndTime().getTime() - p.getExecuteStartTime().getTime();
            vo.setUsed(used);
            vo.setUsedInterval(Utils.interval(used));
        }
        return vo;
    }

//    @Override
//    public String toString() {
//        return "PipelineStaticsLoggerVO{" +
//                "id=" + id +
//                ", uuid=" + uuid +
//                ", title='" + title + '\'' +
//                ", execDate=" + execDate +
//                ", status='" + status + '\'' +
//                ", used=" + used +
//                ", usedInterval='" + usedInterval + '\'' +
//                ", details=" + details.toString() +
//                '}';
//    }
}
